package com.nf.health.app.activity.doctor_advice.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.activity.doctor_advice.adapter.DoctorAdviceByIdAdapter;
import com.nf.health.app.activity.doctor_advice.adapter.SubDoctorAdviceByIdAdapter;
import com.nf.health.app.activity.doctor_advice.bean.AdviceDetail;
import com.nf.health.app.customview.MyListView;
import com.nf.health.app.utils.ViewUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fei on 2016/11/26.
 */

public class MyAdviceDetailQuestionLineaylayout extends LinearLayout implements View.OnClickListener{
    private  LayoutInflater inflater;
    private MyListView mlv_item_byself_ask;
    private TextView tv_time_item_advice_detail;
    private RelativeLayout rl_item_advice_detail_close;
    private ImageView iv_item_advice_detail;
    private SubDoctorAdviceByIdAdapter subDoctorAdviceByIdAdapter = null;
    private  AdviceDetail.QuestionListBean questionListBean ;
    //private  List<AdviceDetail.QuestionListBean.QuestionBean>  subList
    public MyAdviceDetailQuestionLineaylayout(Context context, AdviceDetail.QuestionListBean questionListBean) {
        super(context);
        initData(context,  questionListBean);
    }


    private void initData(Context context, AdviceDetail.QuestionListBean questionListBean){
         inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.item_doctoradvicebyid, this);
        mlv_item_byself_ask = ViewUtil.getView(this,R.id.mlv_item_byself_ask);
        tv_time_item_advice_detail = ViewUtil.getView(this,R.id.tv_time_item_advice_detail);
        rl_item_advice_detail_close = ViewUtil.getView(this,R.id.rl_item_advice_detail_close);
        iv_item_advice_detail = ViewUtil.getView(this,R.id.iv_item_advice_detail);

        //设置问题
        rl_item_advice_detail_close.setOnClickListener(new  MyClickListener(mlv_item_byself_ask,questionListBean));
        iv_item_advice_detail.setOnClickListener(new MyClickListener(mlv_item_byself_ask,questionListBean));

        //设置问题
        List<AdviceDetail.QuestionListBean.QuestionBean>  subList = questionListBean.getQuestion();
        if(subList == null){
            subList = new ArrayList<>();
        }
        if(subDoctorAdviceByIdAdapter == null){
            subDoctorAdviceByIdAdapter = new SubDoctorAdviceByIdAdapter(context,subList,questionListBean.getState(),questionListBean.getId());
            mlv_item_byself_ask.setAdapter(subDoctorAdviceByIdAdapter);
        }else{
            subDoctorAdviceByIdAdapter.setSubDataChanged(subList);
        }
         tv_time_item_advice_detail.setText(""+ questionListBean.getSurveytime());
        if (questionListBean.isOpenStatuis()) {
            mlv_item_byself_ask.setVisibility(View.VISIBLE);
            iv_item_advice_detail.setImageResource(R.drawable.iv_blue_arrowdown);
        } else {
            mlv_item_byself_ask.setVisibility(View.GONE);
            iv_item_advice_detail.setImageResource(R.drawable.iv_blue_arrowup);
        }
    }
    public void setMyQuestionList(List<AdviceDetail.QuestionListBean.QuestionBean> subList){
        if(subList == null){
            return ;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rl_item_advice_detail_close:

                break;
        }
    }
    public class MyClickListener implements View.OnClickListener{
        private MyListView mlv_item_byself_ask;
        private AdviceDetail.QuestionListBean questionListBean;
        public MyClickListener(MyListView mlv_item_byself_ask,AdviceDetail.QuestionListBean questionListBean){
            this.mlv_item_byself_ask = mlv_item_byself_ask;
            this.questionListBean = questionListBean;
        }

        @Override
        public void onClick(View v) {
            if (questionListBean.isOpenStatuis()) {
                mlv_item_byself_ask.setVisibility(View.GONE);
                questionListBean.setOpenStatuis(false);
                iv_item_advice_detail.setImageResource(R.drawable.iv_blue_arrowup);
            } else {
                mlv_item_byself_ask.setVisibility(View.VISIBLE);
                questionListBean.setOpenStatuis(true);
                iv_item_advice_detail.setImageResource(R.drawable.iv_blue_arrowdown);
            }
        }
    }
}
